home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln0286.arc / FACT.C < prev    next >
Text File  |  1986-02-03  |  896b  |  39 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*    fact.c                                */
  4. /*                                    */
  5. /*    Example Program to test recursion.                */
  6. /*                                    */
  7. /*    This program attempts to compute 50! using double's.        */
  8. /*                                    */
  9. /*    A. Skjellum                            */
  10. /*    November 29, 1985                        */
  11. /*                                    */
  12. /*                                    */
  13. /*    Computer Language Magazine [C Interpreter Wrap-Up, Feb., 1986]    */
  14. /*                                    */
  15. /************************************************************************/
  16.  
  17. main()
  18. {
  19.     int iter;
  20.     double factrl();
  21.     double x;
  22.  
  23.     printf("fact.c: computes 50! one hundred times  [29-Nov-85]\n\n");
  24.  
  25.     for(iter = 1; iter <= 100; iter++)
  26.         x = factrl(50.0);
  27.  
  28.     printf("50! = %e\n",x);
  29. }
  30.  
  31. double factrl(x)
  32. double x;
  33. {
  34.     if(x <= 0.0)
  35.         return(1.0);
  36.  
  37.     return(x*factrl(x - 1.0));
  38. }
  39.